<?php

namespace app\product\model;
use think\db\Query;
use think\Model;
use think\facade\Db;
class ProductInventoryModel extends Model
{
    /**
     * 表名
     */
    public $table = 'qu_product_inventory';


    public function attribute_labels_export(){
        $title     = [
            'spu'                     => 'spu',
            'seller_sku'              => 'seller_sku',
            'product_name'            => '产品名称',
            'inventory_quantity'      => '可用库存数量',
            'on_way_quantity'         => '在途数量',
            'not_send_quantity'       => '未发数量',
            'warehouse'               => '仓库',
        ];
        return $title;
    }


    /**
     * @desc  获取满足条件的总计数据
     * @author luckyXiong
     * @date   2024-08-08
     */
    public function pageList($request) {
        // 获取基本参数
        $page  = (isset($request['page']) && $request['page']) ? (int)$request['page'] : 1;
        $limit = (isset($request['limit']) && $request['limit']) ? (int)$request['limit'] : 20;

        // 查询构建
        $query =Db::table('qu_product_inventory t'); // 替换为实际表名，使用别名

        // 执行查询并分页
        $data = $query->page($page, $limit)->select()->toArray(); // 获取结果为数组

        // 总记录数
        $total = $query->count();

        // 返回结果
        return [
            'data'         => $data,
            'total'        => $total,
        ];
    }
}